﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace lindyaka.Library
{
    public static class Entity
    {
        public static void Merge<T>(T target, T source)
        {
            Type t = typeof (T);

            IEnumerable<PropertyInfo> properties = t.GetProperties().Where(prop => prop.CanRead && prop.CanWrite);

            foreach (PropertyInfo prop in properties)
            {
                object value = prop.GetValue(source, null);
                if (value != null)
                {
                    prop.SetValue(target, value, null);
                }
            }
        }
    }
}